home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / ActiveX Controlls / NCTAudioEditor2 ActiveX DLL / NCTAudioEditor2.exe / {app} / Samples / TestBCBAudioEditor2 / Devices.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-10  |  5.5 KB  |  129 lines

  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Devices.h"
  7. #include "Src.h"
  8. #include "Main.h"
  9. #include "Adv.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma resource "*.dfm"
  13. TfrmDevices *frmDevices;
  14. //---------------------------------------------------------------------------
  15. __fastcall TfrmDevices::TfrmDevices(TComponent* Owner)
  16.     : TForm(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. void TfrmDevices::SetSrcOutput(void)
  21. {
  22.     int CountSrc = Dev->DeviceLines->Count;
  23.     for (int i = ComponentCount -1; i > 2; i--) {
  24.         TsrcFrame *sf = (TsrcFrame*)this->Components[i];
  25.         delete sf;
  26.     }
  27.     Width = max(255, CountSrc*79+94);
  28.     Left = (Screen->Width - Width)/2;
  29.     if (CountSrc < 1) return;
  30.     for (int i=ComponentCount-3;i<=CountSrc;i++){                           //Starts a cycle
  31.         TsrcFrame *sf = new TsrcFrame(this);
  32.         sf->Name = AnsiString("sfr")+ AnsiString(i);
  33.         sf->Parent = this;
  34.         sf->Left = i*79+4;
  35.         sf->Top = 48;
  36.         sf->Width = 81;
  37.         Dev->DeviceLines->Num = i;        //sets input source to the current number
  38.  
  39.         sf->Label1->Caption = AnsiString(Dev->DeviceLines->Name); //Sets srcOutput Caption to the src Input device name
  40.         sf->TrackBar1->Position = 65535 - Dev->DeviceLines->Volume; //sets volume value according to the movement of the slider
  41.         sf->TrackBar1->Tag = i;
  42.         sf->TrackBar1->OnChange = TrackBarChange;
  43.         sf->TrackBar2->Position = Dev->DeviceLines->VolumeBalance; //sets balance value according to the slider position
  44.         sf->TrackBar2->Tag = i;
  45.         sf->TrackBar2->OnChange = BalanceTrackBarChange;
  46.         sf->CheckBox1->Checked = (srcCap=="Select") ? Dev->DeviceLines->Select : !Dev->DeviceLines->Select;
  47.         sf->CheckBox1->Tag = i;
  48.         sf->CheckBox1->OnClick = SrcSelectChange;
  49.         sf->CheckBox1->Caption = srcCap;
  50.  
  51.         sf->Button1->Tag = i;
  52.         if (Dev->DeviceLines->AdvancedCount >= 0) sf->Button1->Visible = true; //if the current Src has any advanced options then show "Advanced" button
  53.         else sf->Button1->Visible = false;        //otherwise show no buttons
  54.         sf->Button1->OnClick = AdvClick;
  55.     }
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TfrmDevices::DeviceClick(TObject *Sender)
  59. {
  60.     Dev->Num = (int)Device->Items->Objects[Device->ItemIndex];
  61.     SetSrcOutput();
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TfrmDevices::FormShow(TObject *Sender)
  65. {
  66.     int kDevInput = Dev->Num;        //otherwise kDevOutput equals to the number of output devices on the current machine
  67.     Device->Items->Clear();
  68.     for (int i=0;i<=Dev->Count;i++){               //Start cycle which checks if the current device is able to play sound
  69.         Dev->Num = i;             //Sets number of output device to "i"
  70.         Device->Items->AddObject(Dev->Name, (TObject*)i);
  71.         if (Dev->DeviceLines->Count < 1){
  72.             if (i == kDevInput) kDevInput++;
  73.         }
  74.     }
  75.     if (kDevInput > Dev->Count) kDevInput = 0; //if the number of the alst of all the audio devices is more than number of devices which are able to playback sound
  76.     Dev->Num = kDevInput;        //the number of device for audio output is set to the last device 'been checked
  77.     Device->ItemIndex  = kDevInput;     //the current device to be shown in the Combo box is set to the last device 'been checked
  78.     SetSrcOutput();
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TfrmDevices::TrackBarChange(TObject *Sender)
  82. {
  83.     TTrackBar *TrackBar = (TTrackBar*)Sender;
  84.     TrackBar->Hint = AnsiString(65535-TrackBar->Position);
  85.     TPoint pos;
  86.     GetCursorPos(&pos);
  87.     Application->ActivateHint(pos);
  88.     Dev->DeviceLines->Num = TrackBar->Tag;
  89.     Dev->DeviceLines->Volume = 65535-TrackBar->Position;
  90. }
  91. //---------------------------------------------------------------------------
  92.  
  93. void __fastcall TfrmDevices::AdvClick(TObject *Sender)
  94. {
  95.     TButton *Button = (TButton*)Sender;
  96.     Dev->DeviceLines->Num = Button->Tag;
  97.     TfrmAdv *frm = new TfrmAdv(this);
  98.     frm->m_Rec = true;
  99.     frm->ShowModal();
  100.     delete frm;
  101.  
  102. }
  103. //---------------------------------------------------------------------------
  104.  
  105. void __fastcall TfrmDevices::BalanceTrackBarChange(TObject *Sender)
  106. {
  107.     TTrackBar *TrackBar = (TTrackBar*)Sender;
  108.     Dev->DeviceLines->Num = TrackBar->Tag;
  109.     Dev->DeviceLines->VolumeBalance = TrackBar->Position;
  110. }
  111. //---------------------------------------------------------------------------
  112.  
  113. void __fastcall TfrmDevices::SrcSelectChange(TObject *Sender)
  114. {
  115.     if (flg) return;
  116.     flg = true;
  117.     TCheckBox *CheckBox = (TCheckBox*)Sender;
  118.     Dev->DeviceLines->Num = CheckBox->Tag;
  119.     Dev->DeviceLines->Select = (srcCap == "Select") ? CheckBox->Checked : !CheckBox->Checked;;
  120.     int CountSrc = Dev->DeviceLines->Count;
  121.     for (int i=3;i<=CountSrc+3;i++){                    //Starts a cycle
  122.         Dev->DeviceLines->Num = i-3;                   //sets input source to the current number
  123.         TsrcFrame *sf = (TsrcFrame*)Components[i];
  124.         sf->CheckBox1->Checked = (srcCap == "Select") ? Dev->DeviceLines->Select : !Dev->DeviceLines->Select;
  125.     }
  126.     flg = false;
  127. }
  128. //---------------------------------------------------------------------------
  129.